package analysis.bean;

import common.GlobalConstants;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

public class PlatformDemension extends Unit {
    {
        platform = GlobalConstants.DEFAULT_VALUE;
    }

    public int id;
    public String platform;

    public PlatformDemension() {
    }

    public PlatformDemension(String platform) {
        this.platform = platform;
    }

    public PlatformDemension(int id, String platform) {
        this.id = id;
        this.platform = platform;
    }

    @Override
    public int compareTo(Unit o) {
        PlatformDemension other = (PlatformDemension) o;
        if (this.id != other.id) {
            return this.id - other.id;
        } else {
            if (!this.platform.equals(other.platform))
                return this.platform.compareTo(other.platform);
        }
        return 0;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(this.id);
        dataOutput.writeUTF(this.platform);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.id = dataInput.readInt();
        this.platform = dataInput.readUTF();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PlatformDemension that = (PlatformDemension) o;
        return id == that.id &&
                Objects.equals(platform, that.platform);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, platform);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getPlatform() {
        return platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }
}
